package com.jintoufs.service.weixin.impl;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.jintoufs.dao.wxpay.RefundBackMapper;
import com.jintoufs.dao.wxpay.RefundMapper;
import com.jintoufs.domain.wxpay.Refund;
import com.jintoufs.domain.wxpay.RefundBack;
import com.jintoufs.service.weixin.WxRefundService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

@Service
public class WxRefundServiceImpl implements WxRefundService{
    @Resource
    private RefundMapper refundMapper;
    @Resource
    private RefundBackMapper refundBackMapper;
    @Value("${smsAppid}")
    private Integer smsAppid;
    @Value("${smsAppkey}")
    private String smsAppkey;

    @Override
    public RefundBack findRefundBackById(String id) {
        return refundBackMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteRefundBackById(String id) {
        return refundBackMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertRefundBack(RefundBack refundBack) {
        return refundBackMapper.insertSelective(refundBack);
    }

    @Override
    public int updateRefundBack(RefundBack refundBack) {
        return refundBackMapper.updateByPrimaryKeySelective(refundBack);
    }

    @Override
    public Refund findRefundById(String id) {
        return refundMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteRefundById(String id) {
        return refundMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertRefund(Refund refund) {
        return refundMapper.insertSelective(refund);
    }

    @Override
    public int updateRefund(Refund refund) {
        return refundMapper.updateByPrimaryKeySelective(refund);
    }

    @Override
    public void sendOrderSms(String mobile, int smsId, ArrayList<String> params) {
        try {
            SmsSingleSender sender = new SmsSingleSender(smsAppid, smsAppkey);
            SmsSingleSenderResult result = sender.sendWithParam("86", mobile, smsId, params, "", "", "");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
